package com.cloud.check.api.web;

import com.cloud.check.api.bean.*;
import com.cloud.check.api.service.JgJgdxGthBasicMsgService;
import com.cloud.check.api.service.JgJgdxQyjbxxService;
import com.cloud.check.api.service.RecCheckService;
import com.cloud.check.common.consts.EnumNameConst;
import com.cloud.check.common.exception.BizException;
import com.cloud.check.common.result.Quokka;
import com.cloud.check.common.result.SelectItem;
import com.cloud.check.common.utils.SessionHelper;
import com.cloud.check.interfaces.FeignClientSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("check/api/")
public class CheckController {

	@Autowired
	public RecCheckService recCheckService;

	@Autowired
	public FeignClientSystem feignClientSystem;

	@Autowired
	public JgJgdxGthBasicMsgService jgJgdxGthBasicMsgServiceg;

	@Autowired
	public JgJgdxQyjbxxService jgJgdxQyjbxxService;

	@GetMapping("dicts")
	public Quokka loadDicts(Long sysId) {
		Quokka qk = new Quokka(true);
		Map<String, Object> map = new HashMap<String, Object>();
		List<SelectItem> items = feignClientSystem.findSubjectDomain(SessionHelper.get().getUnitId());
		if(null == items || items.size() == 0){
			throw new BizException(500, "所属部门执法领域未配置");
		}
		map.put("domains", items);
		map.put("counterpartNatures", feignClientSystem.loadDictItems(new Long(15), EnumNameConst.PUNISH_LITIGANT_TYPES));// 当事人类型
		map.put("counterpartCertificateTypes", feignClientSystem.loadDictItems(new Long(15), EnumNameConst.PUNISH_HUMAN_ID_TYPES));// 证件类型
		map.put("superviseObjectTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.SUPERVISE_OBJECT_TYPES));// 监管对象类型
		map.put("checkFormTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.CHECK_FORM_TYPES));// 检查形式
		map.put("checkTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.CHECK_TYPES));// 检查类别
		map.put("checkModeTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.CHECK_MODE_TYPES));// 检查方式
		map.put("checkResultTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.CHECK_RESULT_TYPES));// 检查结果
		map.put("dealTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.DEAL_TYPES));// 检查措施
		map.put("checkItemResultTypes", feignClientSystem.loadDictItems(sysId, EnumNameConst.CHECK_ITEM_RESULT_TYPES));// 检查项检查结果

		qk.setData(map);
		return qk;
	}

	@RequestMapping("address")
	public Quokka loadAddressItems() {
		return new Quokka(true,feignClientSystem.loadAddressItems());
	}

	@RequestMapping("loadhuman")
	public Quokka loadHuman(Long unitId) {
		return new Quokka(true,feignClientSystem.loadHuman(unitId));
	}

	@RequestMapping("saveupdate")
	public Quokka savaUpdate(@RequestBody RecCheckForm recCheckForm) {
		return new Quokka(true, recCheckService.saveUpdate(recCheckForm));
	}

	/**
	 * 分页查询行政检查信息
	 *
	 * @param criteria
	 * @return
	 */
	@RequestMapping("listUnitPage")
	public Quokka listUnitPage(@RequestBody RecCheckCriteriaBean criteria) {
		return new Quokka(true, recCheckService.listUnitPage(criteria));
	}

	/**
	 * 根据Id查找当前检查信息
	 * @param recId
	 * @return
	 */
	@RequestMapping("load")
	public Quokka getRecCheckByRecId(long recId) {
		return new Quokka(true, recCheckService.getRecCheckByRecId(recId));
	}

	/**
	 * 检查分页加载
	 * @param recCheckUnitCriteriaBean
	 * @return
	 */
	@RequestMapping("searchcheckitem")
	public Quokka searchCheckItem(@RequestBody RecCheckUnitCriteriaBean recCheckUnitCriteriaBean) {
		return new Quokka(true, feignClientSystem.searchCheckItem(recCheckUnitCriteriaBean));
	}

	/**
	 * 检查作废
	 * @param recId
	 */
	@RequestMapping("cancel")
	public Quokka deleteCheeckById(Long recId) {
		recCheckService.deleteCheeckById(recId);
		return new Quokka(true);
	}

	/**
	 * 个体工商户自动补全
	 * @param jgJgdxGthBasicMsgBean
	 * @return
	 */
	 @RequestMapping("busines")
	 public Quokka  searchBusines(@RequestBody JgJgdxGthBasicMsgBean jgJgdxGthBasicMsgBean) {
		 return new Quokka(true,jgJgdxGthBasicMsgServiceg.searchBusiness(jgJgdxGthBasicMsgBean));
	 }

	/**
	 * 法人自动补全
	 * @param jgJgdxQyjbxxBean
	 * @return
	 */
	@RequestMapping("corporation")
	public Quokka  searchcorporation(@RequestBody JgJgdxQyjbxxBean jgJgdxQyjbxxBean) {
		return new Quokka(true, jgJgdxQyjbxxService.searchCorporation(jgJgdxQyjbxxBean));
	}
}
